  define(function(){


  function bannerFn(dat){

    // 获取轮播图展示窗口
    var $banner = $('#banner');
    // 获取包裹图片的div
    var $bannerDivs = $('#bannerDivs');

    var $datObj = dat.data.act_info[0].act_rows;
    // console.log($datObj);
    for(var $dataImg of $datObj){
      var $imgUrl = $dataImg.activity.img;
      // console.log($imgUrl)
      var $img = $('<img />').attr("src",$imgUrl).appendTo($bannerDivs).width($banner.width()).height($banner.height());
    }
    $bannerDivs.css({
      "display":"flex",
      "transition": 'all 1s',
      "position":"absolute",
    })
    //获取可轮播的图的个数
    $imgs = $("#bannerDivs>img");
    $bannerDivs.width($imgs.length *$banner.width())
    // console.log($bannerDivs.width())
    // lunboFn();
    var index = 0;
    var $timer = setInterval(function(){index++;lunboFn()},3000);
    function lunboFn(){
      // 获取轮播图展示窗口
      // 获取包裹图片的div
      // index++;

      if (index >= $imgs.length) {
        index = 0;
      }
      var Left = index * $banner.width() *(-1);
      $bannerDivs.offset({left:Left})
    }
  }





    //4个推荐图标(每日必抢)
    function recommendFn(d){

        var $recommend = $('#recommend');
        var $dArr = d.data.act_info[1].act_rows;
        // console.log($dArr);
        for(var $newObj of $dArr){
          var $imgUrl = $newObj.activity.img;
          // console.log($imgUrl)
          var $div = $('<div></div>').appendTo($recommend);
          var $img = $('<img />').attr("src",$imgUrl).appendTo($div);

          var $text = $newObj.activity.name
          var $p = $('<p></p>').text($text).appendTo($div);
        }
    }

    // 3个广告图
    function guanggaotuFn(d2){
      var $guanggaotu = $('#guanggaotu');
      var $d2Arr = d2.data.act_info[3].act_rows;
      // console.log($d2Arr)
      for(var $newObj of $d2Arr){
        var $imgUrl = $newObj.activity.img;

        var $div = $('<div></div>').appendTo($guanggaotu);
        var $img = $('<img />').attr("src",$imgUrl).appendTo($div);

      }
    }

    //便利店
    function bianlidianFn(d3){
      var $d3Arr = d3.data.act_info[4].act_rows[1].act_rows;
      // console.log($d3Arr);
      // 畅销榜
      var $bian2 = $('.bian2');
      for(var $newObj of $d3Arr){
        var $imgUrl = $newObj.cactivity_detail.img;
        var $a = $('<a></a>').attr("href","#").appendTo($bian2);
        var $div = $('<div></div>').appendTo($a);
        var $img = $('<img />').attr("src",$imgUrl).appendTo($div);
      }

      // 4个图标
      var $bian3 = $('.bian3');
      var $d32Arr = d3.data.act_info[4].act_rows[2].act_rows;
      // console.log($d32Arr);
      for (var $newData of $d32Arr){
        var $imgurl = $newData.cicons_detail.img;
        var $text = $newData.cicons_detail.name;

        var $a1 = $('<a></a>').attr("href","#").appendTo($bian3);
        var $div1 = $('<div></div>').appendTo($a1);
        var $img1 = $('<img />').attr("src",$imgurl).appendTo($div1);
        var $p = $('<p></p>').text($text).appendTo($div1);
      }

      // 2个广告图
      var $bian4 = $('.bian4');
      var $d33Arr = d3.data.act_info[4].act_rows[3].act_rows;
      // console.log($d33Arr);
      for (var $newData2 of $d33Arr){
        var $imgurl2 = $newData2.cscene_detail.img;

        var $a2 = $('<a></a>').attr("href","#").appendTo($bian4);
        var $div2 = $('<div></div>').appendTo($a2);
        var $img2 = $('<img />').attr("src",$imgurl2).appendTo($div2);
      }
    }


    // 优选水果
    function youxuanFn(d4){
        var $newA = d4.data.act_info[5].act_rows;
        // console.log($newA)

        var $Box = $('#BOX');
        for(var $newData3 of $newA){
          // console.log($newData3);
          //创建包含一个模块的的大div
          var $Div = $('<div></div>').attr("id","youxuanBox").appendTo($Box);

            //获取标题
          var $titleName = $newData3.category_detail.name;
            //获取标题颜色
          var $titleColor = $newData3.category_detail.category_color;
            //创建模块的标题DIV
          var $title = $('<div></div>').addClass("youxuanTitle").appendTo($Div);
          //创建模块的标题左文字
          var $titleText = $('<div></div>').text($titleName).css({
            "color":"#"+$titleColor,
            "font-size": "0.3rem",
    				"font-weight": "600",
    				"padding-left": "0.1rem",
    				"border-left": "0.2rem solid #"+$titleColor
          }).appendTo($title);

          var $titleMore = $('<div></div>').appendTo($title);
          var $titlea = $('<a></a>').attr("href","#").text("更多 >").appendTo($titleMore);


          //获取广告图地址
          var $bannerUrl = $newData3.activity.img;
          // console.log($bannerUrl)
          //创建中间的banner
          var $bannerMid = $('<div></div>').css({
            "width": "100%",
    				"height": "1.5rem",
            "background":"url("+$bannerUrl +") no-repeat",
            "background-size":"100% 100%",
            "margin-bottom": "0.2rem"

          }).appendTo($Div);

          //三个列表商品
          //创建一个包含3个商品的div
          $mainDiv = $('<div></div>').css({
            "width": "100%",
    				"height": "3.5rem",
    				"display": "flex",
    				"justify-content": "space-between"
          }).appendTo($Div);

          var $dataNew = $newData3.category_detail.goods;
          // console.log($dataNew)
          for(var $ndata of $dataNew){
            // for(var i=0; i<$dataNew.length; i++){
              var $mainBox = $('<div></div>').appendTo($mainDiv).css({
                "width": "33%",
        				"height": "3.5rem",
        				"background-color": "white"
              });
              // }
              var $ImgBox = $('<div></div>').appendTo($mainBox);
              var $Imgurl = $ndata.img;
              // console.log($ndata)
              var $mainImg = $('<img />').attr("src",$Imgurl).appendTo($ImgBox).css("width","96%");

              var $mainText = $('<div></div>').addClass("yxMain1-text").appendTo($mainBox);
              //获取图片文字
              var $textStr = $ndata.name;
              var $mainp = $('<p></p>').text($textStr).appendTo($mainText);

              //精选
              if($ndata.source_id == "1"){
                var $mainJx = $('<div></div>').addClass("yxMain1-jx").text("精选").appendTo($mainText)
              }

              //量
              var $mainKgStr = $ndata.specifics;
              // console.log($mainKgStr)
              var $mainKg = $('<div></div>').addClass("yxMain1-kg").text($mainKgStr).appendTo($mainText)

              //价格
              var $mainPrice = $('<div></div>').addClass("yxMain1-price").appendTo($mainText);
              //新价
              var $newStr = $ndata.price;
              var $newspan = $('<span></span>').text($newStr).appendTo($mainPrice);
              var $oldStr = $ndata.d_price;
              var $oldspan = $('<span></span>').text($oldStr).appendTo($mainPrice);

              var $price3 = $('<span></span>').text("╋").appendTo($mainPrice)
            }
          }
        }

        return {
          bannerFn:bannerFn,
          recommendFn:recommendFn,
          guanggaotuFn:guanggaotuFn,
          bianlidianFn:bianlidianFn,
          youxuanFn:youxuanFn
          // lunboFn:lunboFn,
        }
      })
